﻿using System;
using System.Windows.Forms;
using aboveXWords.GUI;

namespace aboveXWords
{
  public partial class QuestionDialog : Form
  {
    private readonly Canvas m_canvas;
    private readonly Question m_question;
    private readonly string m_text;

    public QuestionDialog(Canvas canvas, Question question)
    {
      m_canvas = canvas;
      m_question = question;
      m_text = m_question.Value;
      InitializeComponent();
      textBoxQuestion.Text = m_text;
    }

    private void TextBoxQuestionTextChanged(object sender, EventArgs e)
    {
      m_question.Value = textBoxQuestion.Text;
      m_question.Invalidate(m_canvas);
    }

    private void QuestionDialog_FormClosing(object sender, FormClosingEventArgs e)
    {
      m_question.Value = DialogResult == DialogResult.OK ? textBoxQuestion.Text : m_text;
      m_question.Invalidate(m_canvas);
    }
  }
}